<template>
  <div style="margin-top:30px">
    <el-form ref="form" :rules="rules" :model="form" label-width="100px">
      <el-row>
        <div class="grid-content bg-purple">
          <el-form-item label="上传附件" style="margin-right:15px">
            <el-col :span="24">
              <el-upload
                class="upload-demo"
                :action="uploadUrl"
                :on-remove="handleRemove"
                :before-remove="beforeRemove"
                :on-success="handleSuccess"
                multiple
                :limit="3"
                :on-exceed="handleExceed"
                :file-list="fileList"
                :headers="getAuthorization()"
              >
                <el-button size="small" type="primary">点击上传</el-button>
              </el-upload>
            </el-col>
          </el-form-item>
        </div>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="App名称" style="margin-right:15px">
              <el-input v-model="form.name" :disabled="true" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="App大小" style="margin-right:15px">
              <el-input v-model="form.size" :disabled="true" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="App类型" prop="type" style="margin-right:15px">
              <el-select v-model="form.type" placeholder="请选择">
                <el-option label="司机端" value="tmsDriver"></el-option>
                <el-option label="入驻商端" value="tmsShipper"></el-option>
              </el-select>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="App版本" prop="version" style="margin-right:15px">
              <el-input v-model="form.version" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="自动更新" style="margin-right:15px">
              <el-radio-group v-model="form.openUpdate">
                <el-radio :label="1">开启</el-radio>
                <el-radio :label="0" selected>关闭</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="强制更新" style="margin-right:15px">
              <el-radio-group v-model="form.forceUpdate">
                <el-radio :label="1">开启</el-radio>
                <el-radio :label="0" selected>关闭</el-radio>
              </el-radio-group>
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="更新内容" style="margin-right:15px">
              <el-input type="textarea" v-model="form.content" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="下载链接" prop="link" style="margin-right:15px">
              <el-input v-model="form.link" :disabled="true" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
      <el-row hidden>
        <el-col :span="24">
          <div class="grid-content bg-purple">
            <el-form-item label="二维码" style="margin-right:15px">
              <el-input v-model="form.qrCode" />
            </el-form-item>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="funcCancel">取 消</el-button>
      <el-button type="primary" @click="funcSubmit">确 定</el-button>
    </div>
  </div>
</template>
<script>
import Vue from "vue";
import "xe-utils";
import VXETable from "vxe-table";
import "vxe-table/lib/index.css";
import { AppUploadAdd } from "@/api/statistics";
Vue.use(VXETable);
export default {
  name: "partyGroupConfigAdd",
  data() {
    return {
      uploadUrl: this.BASE_API_URL + "ntocc-tps-api/fileUpload",
      fileList: [],
      form: {
        id: "",
        name: "",
        type: "",
        size: "",
        sha1: "",
        link: "",
        qrCode: "",
        version: "",
        openUpdate: 0,
        forceUpdate: 0,
        content: "",
      },
      rules: {
        link: [{ required: true, message: "请上传文件", trigger: "blur" }],
        type: [{ required: true, message: "请选择类型", trigger: "blur" }],
        version: [{ required: true, message: "请输入版本", trigger: "blur" }],
        content: [
          { required: true, message: "请输入修改内容", trigger: "blur" }
        ]
      }
    };
  },
  created() {},
  methods: {
    //提交
    funcSubmit() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          const rLoading = this.openLoading();
          AppUploadAdd(this.form).then(response => {
            rLoading.close();
            this.$message({
              message: response.msg,
              type: "success"
            });
            this.form = null;
            this.$emit("fatherAddMethod");
          });
        } else {
          return false;
        }
      });
    },
    //取消
    funcCancel() {
      this.$emit("fatherCancelMethod", "add");
    },
    handleRemove(file, fileList) {
    },
    handleSuccess(res, file) {
      this.$message({ message: res.msg, type: "success" });
      this.form.link = res.data;
      this.form.size = file.size;
      this.form.name = file.name;
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${
          files.length
        } 个文件，共选择了 ${files.length + fileList.length} 个文件`
      );
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    }
  }
};
</script>
<style lang="scss" scoped>
.dialog-footer {
  margin: 15px 0 15px 0;
  width: 175px;
  float: right;
}
.el-select {
  width: 100%;
}
.el-date-editor {
  width: 100%;
}
</style>

